package com.coda.controller;


import com.coda.common.PageResult;
import com.coda.common.Result;
import com.coda.dto.PageDto;
import com.coda.entity.InStore;
import com.coda.entity.Purchase;
import com.coda.entity.Store;
import com.coda.service.InStoreService;
import com.coda.service.PurchaseService;
import com.coda.service.StoreService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/warehouse/purchase")
public class PurchaseController {

    @Autowired
    private PurchaseService purchaseService;
    @Autowired
    private StoreService storeService;
    @Autowired
    private InStoreService inStoreService;

    /**
     * 添加采购单
     */
    @PostMapping("/purchase-add")
    @ApiOperation("添加采购单")
    public Result addPurchase(@RequestBody Purchase purchase) {
        purchaseService.addPurchase(purchase);
        return Result.ok("添加成功");
    }

    /**
     * 查询仓库列表
     */
    @GetMapping("/store-list")
    @ApiOperation("查询仓库列表")
    public Result getStoreList(){
        List<Store> storeList = storeService.getStoreList();
        return Result.ok(storeList);
    }

    /**
     * 分页查询采购列表
     */
    @GetMapping("/purchase-page-list")
    @ApiOperation("分页查询采购列表")
    public Result getPurchasePage(PageDto pageDto,  Purchase purchase){
        PageResult purchaseList = purchaseService.getPurchasePage(pageDto,purchase);
        return Result.ok(purchaseList);
    }

    /**
     * 根据id删除采购单
     */
    @DeleteMapping("/purchase-delete/{id}")
    @ApiOperation("根据id删除采购单")
    public Result deletePurchase(@PathVariable Long id){
        purchaseService.deletePurchase(id);
        return Result.ok("删除成功");
    }

    /**
     * 根据id修改采购单
     */
    @PutMapping("/purchase-update")
    @ApiOperation("根据id修改采购单")
    public Result updatePurchase(@RequestBody Purchase purchase){
        purchaseService.updatePurchase(purchase);
        return Result.ok("修改成功");
    }

    /**
     * 生成表单入库
     */
    @PostMapping("/in-warehouse-record-add")
    @ApiOperation("生成表单入库")
    public Result addInStore(@RequestBody Purchase purchase){
        inStoreService.addInstore(purchase);
        return Result.ok("生成成功");
    }

}
